/**
 * Created by Cyril on 16/8/17.
 */
import _ from 'lodash'
import dateFns from 'date-fns'

const CONFIG_MAP = {
  default: {
    APIHOST: window.location.protocol + '//' + window.location.host + '/api',
    ORIGINHOST: window.location.protocol + '//' + window.location.host + '/origin'
  },
  development: {
    env: 'development',
    color: '#28d3a9'
  },
  production: {
    env: 'production',
    color: '#fb054c'
  },
  custom: {
    env: 'custom',
    color: '#f90',
    APIHOST: window.CUSTOM_APIHOST
  }
}

function config (env) {
  return _.assign(
    {},
    CONFIG_MAP['default'],
    CONFIG_MAP[env || 'development'] || {}
  )
}

var result = config(window.BUILD_ENV || process.env.NODE_ENV)
var buildDate = dateFns.format(new Date(), 'YYYY-MM-DD HH:mm:ss')
console.log(
  '%cBuild ENV:  ' + result.env.toUpperCase(),
  `padding: 6px 12px;font-size: 14px;min-height: 32px;line-height: 1;color: #fff;background-color:${
    result.color
  };border-color:${
    result.color
  };border-radius: 2px; margin: 5px 0;line-height: 40px;`
)
console.log(
  '%cBuild DATE: ' + buildDate,
  'padding: 6px 12px;font-size: 14px;min-height: 32px;line-height: 1;color: #fff;background-color: #0099ff;border-color: #0099ff;border-radius: 2px; margin: 5px 0;line-height: 40px;'
)
// Say hello to debuggers.
console.log(
  '%c' + '😉 What are you looking for ???'.toUpperCase(),
  'padding: 6px 12px;font-size: 14px;min-height: 32px;line-height: 1;color: #fff;background-color: #b100ff;border-color: #b100ff;border-radius: 2px; margin: 5px 0;line-height: 40px;'
)

export default result
